#include "clock.h"
#include "isr.h"
#include "common.h"

uint tick = 0;

static void clock_callback(registers_t regs){
	tick++;
//	printk("Tick: %d.\n", tick);
}

void init_clock(uint frequency){
	register_interrupt_handler(IRQ0, &clock_callback);
	
	uint divisor = 1193180 / frequency;
	
	outb(0x43, 0x36);
	
	// Divisior has to be sent bytewise.
	// Hence, the split
	uint8 l = (uint8)(divisor & 0xFF);
	uint8 h = (uint8)( (divisor >> 8) & 0xFF);
	
	// Send the frequency divisor.
	outb(0x40, l);
	outb(0x40, h);
}

